<?php
// +----------------------------------------------------------------------
// | wttai [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.wttai.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 老司机 <wutongtai@wttai.com> <http://www.wttai.com>
// +----------------------------------------------------------------------
namespace Home\Controller;
use Think\Log;
/**
 * 检测贴图库的数据
 * 
 */
class PicController extends HomeController
{

   
    public function dealImg($img)
    {
        if($img){
        
         //是否存在贴图库，则重新获取
            $map=img_exist($img);
            
            //未存在贴图库,传图到贴图库
            if(!$map){ 
                //查询出当前文章的文章内容
               $url=$_SERVER['HTTP_REFERER'];
               //判断是否有id值
               $idPosition=strpos('/id/',$url);
               if($idPosition){
                 $id=substr($url, $idPosition,-5);  
               }else{
                   $idPosition=strrpos('/',$url);
                   $name=substr($url, $idPosition,-5);
                   $id=M('Document')->where(array('name'=>$name))->getField('id');
               }
               $ArContent=M('DocumentArticle')->where(array('id'=>$id))->find($detail);
               $content=$ArContent['content'];
               $detail=tietu($img);//http://www.wen0.cn/home/Pic/dealImg?img=http://i4.buimg.com/590929/ae155a1c35bc719f.jpg
               $img="src='http://".$_SERVER['HTTP_HOST']."/home/Pic/dealIm?img=".$img."'".
               $del_content['content']=str_replace($img, $detail, $content);
               M('DocumentArticle')->where(array('id'=>$id))->save($del_content);
            }
        } 
        
        //获得贴图库地址
        header("Location:$img");
    }
        

}
